﻿using System;
using Enterprise.Framework.Core.Container;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Domain.Model;
using Resto.CostControl.Core.Domain.Query.DishModule;
using Resto.CostControl.Core.Facade.DishModule.DataTransferObject;

namespace Resto.CostControl.Core.Facade.DishModule.FacadeObject
{
    /// <summary>
    /// 每周菜肴,项目点没有可选择的菜肴
    /// </summary>
    public class WeekDishFO : IApplicationFacadeObject
    {
        #region 私有属性

        private WeekDishDQO _WeekDishDQO;
        private WeekDishDQO WeekDishDQO
        {
            get
            {
                if (_WeekDishDQO == null)
                    _WeekDishDQO = ObjectCreator.Create<WeekDishDQO>();

                return _WeekDishDQO;
            }
        }

        #endregion

        #region 公共方法

        public virtual void AddWeekDish(WeekDishDTO dishDTO)
        {
            WeekDish dish = dishDTO.ToWeekDish();
            
            dish.Add();

            RestoCostDomainSession.CurrentSession.SaveChanges();

            dishDTO.ID = dish.ID;
        }

        public virtual void UpdateWeekDish(WeekDishDTO dishDTO)
        {
            WeekDish dish = WeekDishDQO.GetWeekDish(dishDTO.ID);
            dishDTO.CopyToWeekDish(dish);

            RestoCostDomainSession.CurrentSession.SaveChanges();

        }

        public virtual WeekDishDTO GetWeekDishDTO(DateTime time)
        {
            WeekDish dish = WeekDishDQO.GetWeekDish(time);
            if (dish == null)
                return null;

            return new WeekDishDTO(dish);
        }

        

        #endregion

       
    }
}
